package base.tree.search.midOrder;

import base.tree.TreeNode;

import java.util.Stack;

/**
 * 二叉树非递归遍历
 */
public class Solution {
    //中序递归遍历
    public void midOrderRe(TreeNode node){
        if (node==null){
        }else{
            midOrderRe(node.left);
            System.out.println(node.val);
            midOrderRe(node.right);
        }

    }

    //中序非递归遍历
    public void midOrder(TreeNode node){
        Stack<TreeNode> stack = new Stack<>();

        while(!stack.empty()||node!=null){
            while(node!=null){
                stack.push(node);
                node=node.left;
            }

            if(!stack.empty()){
                node= stack.pop();
                System.out.println(node.val);
                node=node.right;
            }
        }

    }
}
